<template>
    <div class="sidebar">
       <el-menu :default-active="onRoutes" class="el-menu-vertical-demo" background-color="#2f4056" text-color="#fff" theme="dark" unique-opened router>
            <template v-for="item in items" >
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.id">
                        <template slot="title" class="menu-left"><i :class="item.icon"></i>{{ item.title }}</template>
                        <el-menu-item v-for="(subItem,i) in item.subs" :key="i" :index="subItem.index">{{ subItem.title }}
                        </el-menu-item>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.id">
                        <i :class="item.icon"></i>{{ item.title }}
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
export default {
  data() {
    return {
      items: [
        {
          icon: "el-icon-setting",
          index: "allbook",
          title: "书籍管理"
        },
        {
          icon: "el-icon-setting",
          index: "BookSearch",
          title: "搜索书籍"
        },
        {
          icon: "el-icon-setting",
          index: "alluser",
          title: "所有账号数据"
        },
        {
          icon: "el-icon-menu",
          index: "2",
          title: "个人中心",
          subs: [
            {
              index: "myallborrow",
              title: "所借书籍"
            },
            {
              index: "vuetable",
              title: "个人信息"
            }
          ]
        }
      ]
    };
  },
  computed: {
    onRoutes() {
      return this.$route.path.replace("/", " ");
    }
  }
};
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  width: 200px;
  height: calc(100vh - 60px);
  color: #c0c5cc;
}
.sidebar > ul {
  height: 100%;
}
.el-menu-vertical-demo {
  float: left;
  width: 100%;
}
.menu-left {
  float: left;
}
</style>
